package action.general;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import service.properties.ConfigurationCheminsProperties;
import service.securite.DroitsAcces;


import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionServlet;

import bean.dossier.Dossier;

public class NotreServlet extends Action {
	private static final long serialVersionUID = 4785169243852951116L;

	
	public ActionForward execute(final ActionMapping pMapping,
			ActionForm pForm, final HttpServletRequest pRequete,
			final HttpServletResponse pReponse) {
		
		String dossierSite = Dossier.getDossierSite();
		String dossierAdmin = Dossier.getDossierAdmin();
		String dossierImages = Dossier.getDossierImages();
		String dossierJS = Dossier.getDossierJS();
		String dossierCSS = Dossier.getDossierCSS();
		String dossierFactures = Dossier.getDossierFactures();
		String dossierBonsCommande = Dossier.getDossierBonsCommande();
		String dossierProduits = Dossier.getDossierProduits();
		
		HttpSession session = pRequete.getSession();
		if (session == null)
			return pMapping.findForward("error");
		session.setAttribute("dossierSite", dossierSite);
		session.setAttribute("dossierAdmin", dossierAdmin);
		session.setAttribute("dossierImages", dossierImages);
		session.setAttribute("dossierJS", dossierJS);
		session.setAttribute("dossierCSS", dossierCSS);
		session.setAttribute("dossierFactures", dossierFactures);
		session.setAttribute("dossierBonsCommande", dossierBonsCommande);
		session.setAttribute("dossierProduits", dossierProduits);
		if (!DroitsAcces.isConnecte(pRequete))
			DroitsAcces.setInvite(session);
				return pMapping.findForward("success");
		
	}
		
	public static void checkParametresPagination(HttpServletRequest request) throws NumberFormatException {
		String strDebut = (String)request.getParameter("debut");
		String strNb = (String)request.getParameter("nb");
		if (strDebut != null || strNb != null) {
			int debut = Integer.parseInt(strDebut);
			int nb = Integer.parseInt(strNb);
			if (debut <= 0 || nb <= 0)
				throw new NumberFormatException();
		}
	}
}
